import * as THREE from 'three';

// const geometry = new THREE.SphereGeometry(30);
const geometry = new THREE.BufferGeometry();

const vertices = new Float32Array( [
    0, 0, 0, //顶点1坐标   0
    160, 0, 0, //顶点2坐标  1
    160, 80, 0, //顶点3坐标  2
    0, 80, 0, //顶点6坐标  3
] );
//创建属性缓冲区对象
const attribue = new THREE.BufferAttribute( vertices, 3 ); //3个为一组，表示一个顶点
//设置几何体attributes属性的位置属性
geometry.attributes.position = attribue;

const indexes  = new Uint16Array([0,1,2,0,2,3])
// 索引数据赋值给几何体的index属性
geometry.index = new THREE.BufferAttribute( indexes, 1 ); // 1个为一组


const uvs = new Float32Array( [
    0, 0, //顶点1坐标   uv坐标
    0.5, 0, //顶点2坐标  1
    0.5, 0.5, //顶点3坐标  2
    0, 0.5, //顶点6坐标  3
] );
geometry.attributes.uv = new THREE.BufferAttribute( uvs, 2 );


// 创建纹理加载器对象
const loaderTex = new THREE.TextureLoader();
// 加载图片返回一个纹理对象
const texture = loaderTex.load('./earth.jpg')

const material = new THREE.MeshBasicMaterial({ 
    // 设置材质的颜色贴图
    map: texture,
    side: THREE.DoubleSide,
})
// material.map = texture;


const mesh = new THREE.Mesh(geometry, material);




export default mesh;